package com.dsbj.mp.icardservice.service.physicalcondition;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dsbj.mp.icardservice.entity.DayPhysicalCondition;
import com.dsbj.mp.icardservice.mapper.DayPhysicalConditionMapper;
import com.dsbj.mp.icardservice.utils.strprocess.Time_convert;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 每日健康检查表 服务实现类
 * </p>
 *
 * @author cjw
 * @since 2020-02-10
 */
@Service
@Transactional
public class DayPhysicalConditionService extends ServiceImpl<DayPhysicalConditionMapper, DayPhysicalCondition> {
	
	@Resource
	private DayPhysicalConditionMapper dayPhysicalConditionMapper;
	
	
	
	/**
	 * 根据idcardno,checkTime获取dayPhysicalCondition。
	 * @params
	 * @return
	 * @author cjw 2020/2/10
	 */
	public DayPhysicalCondition getDayPhysicalConditionByCheckTime(String idcardno,String checkTime){
		QueryWrapper<DayPhysicalCondition> queryWrapper=new QueryWrapper<DayPhysicalCondition>()
				.eq("IDCARDNO", idcardno)
				.eq("TO_CHAR(CHECK_TIME, 'yyyy-mm-dd')", checkTime)
				.orderByDesc("CREATE_TIME");
		List<DayPhysicalCondition> list_dayPhysicalCondition=dayPhysicalConditionMapper.selectList(queryWrapper);
		if(list_dayPhysicalCondition.size()>0){
			return list_dayPhysicalCondition.get(0);
		}
		return null;
	}
	
	/**
	 * 获取"今日已打卡"的员工的身份证号。
	 * @param
	 * @return
	 * @author cjw 2020-02-25
	 */
	public List<String> getDayPhysicalConditionIdcardnoByCheckTime_today(){
		String dateStr=Time_convert.getCurrentTime().substring(0,10);
		QueryWrapper<DayPhysicalCondition> queryWrapper=new QueryWrapper<DayPhysicalCondition>()
				.select("IDCARDNO")
				.eq("TO_CHAR(CHECK_TIME,'yyyy-mm-dd')",dateStr)
				.eq("STATUS",1)
				.orderByDesc("CREATE_TIME");
		List<DayPhysicalCondition> list_dayPhysicalCondition=dayPhysicalConditionMapper.selectList(queryWrapper);
		
		//返回"今日已打卡"的员工的身份证号列表
		List<String> list_idcardno=null;
		list_idcardno=list_dayPhysicalCondition.stream().map(DayPhysicalCondition::getIdcardno).collect(Collectors.toList());
		return list_idcardno;
	}
	
	
	public List<DayPhysicalCondition> getTemperatureData(String idcardno){
	    return dayPhysicalConditionMapper.getTemperatureData(idcardno);
    }
	
	
    
}
